﻿app.controller('CommentController', ['$scope', '$location','CommentService', function ($scope, $location, NoteFactory) {
    $scope.comment = CommnetService.comment;

    if ($scope.$parent.status.isLoggedIn) {
        $scope.newComment = {};

        $scope.editComment = {};

        $scope.addComment = function () {
            CommentService.addComment($scope.newComment);
            $scope.newComment = {};
        };

        $scope.updateComment = function (i) {
            NoteFactory.updateComment(i, $scope.editComment);
            $scope.editNote = {};
        };

        $scope.deleteComment = function (i) {
            CommentService.deleteComment(i);
        };

        $scope.getComments = function () {
            NoteFactory.getComments();
        };
    }

        CommentsService.postComment(data)
          .then(function () {
              $scope.commentsForm.$setPristine();
              $scope.c = {};
          }, function () {
              $scope.c.alert = true;
          });
    };

    $scope.toggleCommentForm = function () {
        $scope.commentForm.hide = !$scope.commentForm.hide;
    };
}]);